package lv.clientedisqueria.model;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.List;
import java.util.Observable;

import lv.mensajeriadisqueria.idomain.IDomain;

public abstract class Modelo<Entity extends IDomain> extends Observable {

	public static final String INSERTAR = "insertar";
	public static final String MODIFICAR = "modificar";
	public static final String BORRAR = "borrar";
	public static final String CANCELAR = "cancelar";
	public static final String GUARDAR = "guardar";
	public static final String GUARDADO = "guardado";
	
	private PropertyChangeSupport propertyChange = new PropertyChangeSupport(this);
	
	public synchronized void addPropertyChangeListener(String propertyName, PropertyChangeListener listener){
		propertyChange.addPropertyChangeListener(propertyName, listener);
	}
	
	public synchronized void addPropertyChangeListener(PropertyChangeListener listener){
		propertyChange.addPropertyChangeListener(listener);
	}
	
	public void firePropertyChange(String propertyName, Object oldValue, Object newValue){
		propertyChange.firePropertyChange(propertyName, oldValue, newValue);
	}
	
	public void firePropertyChange(PropertyChangeEvent evt){
		propertyChange.firePropertyChange(evt);
	}
	
	public synchronized PropertyChangeListener[] getPropertyChangeListener(String propertyName){
		return propertyChange.getPropertyChangeListeners(propertyName);
	}

	public void notificar(String mensaje) {
		setChanged();
		notifyObservers(mensaje);
	}
	
	public void modificar() {
		notificar(Modelo.MODIFICAR);
	}

	public abstract String getPropertyChangeCambio();

	public abstract List<Entity> buscarTodos();
	
	public abstract void borrar();
	
	public abstract void insertar();
	
	public abstract void guardar(Entity entity);
	
	public abstract DisqueriaTablaModelo<Entity> getTablaModel();
}
